export default class SRM {
    // Refer to https://github.com/lo-tp/memory-scheduler
    constructor(
        intervals = [1, 2, 3, 8, 17],
        scroreToProgressChange = [-3, -1, 1]
    ) {
        this.intervals = intervals;
        this.scroreToProgressChange = scroreToProgressChange;
    }

    get maxProgress() {
        return this.intervals.length;
    }
    get correctScore() {
        return this.scroreToProgressChange.length - 1;
    }
    calculate(s, { progress }, now) {
        const correct = s === this.scroreToProgressChange.length - 1;

        const newProgress = progress + this.scroreToProgressChange[s];

        let dueDate = now + 1;
        if (correct && progress < this.maxProgress) {
            dueDate = now + this.intervals[progress];
        }

        console.log("correct=", s, " progress=", progress, " scroreToProgressChange=", this.scroreToProgressChange[s], " intervals=", this.intervals[progress]);
        return {
            dueDate,
            progress: newProgress < 0 ? 0 : newProgress
        };
    }
    getInitialRecord(now) {
        return {
            progress: 0,
            dueDate: now
        };
    }
}